package com.bingxu.flink.chapter02.transformation;

import com.bingxu.flink.bean.WaterSensor;
import org.apache.flink.api.common.functions.MapFunction;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.datastream.SingleOutputStreamOperator;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

/**
 * @author :BingXu
 * @description :TODO
 * @date :2021/8/9 11:34
 * @modifier :
 */

public class Trans_Map {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        DataStreamSource<String> source = env.socketTextStream("localhost", 8989);

        source.map(new MapFunction<String, WaterSensor>() {

            @Override
            public WaterSensor map(String value) throws Exception {
                String[] params = value.split(",");
                return new WaterSensor(params[0],Long.parseLong(params[1]),Integer.valueOf(params[2]));
            }
        })
                .print();

        env.execute();

    }
}
